package com.atguigu.aclservice.service.impl;

import com.atguigu.aclservice.entity.User;
import com.atguigu.aclservice.mapper.UserMapper;
import com.atguigu.aclservice.service.UserService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

/**
 * <p>
 * 用户表 服务实现类
 * </p>
 *
 * @author fxy
 * @since 2022-10-27
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    //更改用户状态
    @Override
    public void updateStatus(Long id, Integer status) {
        //根据用户id查询
        User sysUser = baseMapper.selectById(id);
        //设置修改状态
        sysUser.setStatus(status);
        //调用方法修改
        baseMapper.updateById(sysUser);
    }

//    @Override
//    public void updateLoginTimeAndIp(Long id, Date date, String hostAddress) {
//        this.baseMapper.updateLoginTimeAndIp(id,date,hostAddress);
//    }

    @Override
    public void updatePersonAvatar(Long id, String avatar) {
        this.baseMapper.updatePersonAvatar(id,avatar);
    }

    @Override
    public void updatePersonPassword(Long id, String newPassword) {
        this.baseMapper.updatePersonPassword(id,newPassword);
    }

    @Override
    public User getUserInfoByUserName(String username) {
        QueryWrapper<User> wrapper = new QueryWrapper<>();
        wrapper.eq("username",username);
        return baseMapper.selectOne(wrapper);
    }

//    //username查询
//    @Override
//    public SysUser getUserInfoByUserName(String username) {
//        QueryWrapper<SysUser> wrapper = new QueryWrapper<>();
//        wrapper.eq("username",username);
//        return baseMapper.selectOne(wrapper);
//    }

//    //根据用户名称获取用户信息（基本信息 和 菜单权限 和 按钮权限数据）
//    @Override
//    public Map<String, Object> getUserInfo(String username) {
//        //根据username查询用户基本信息
//        SysUser sysUser = this.getUserInfoByUserName(username);
//        //根据userid查询菜单权限值
//        List<RouterVo> routerVolist = sysMenuService.getUserMenuList(sysUser.getId());
//        //根据userid查询按钮权限值
//        List<String> permsList = sysMenuService.getUserButtonList(sysUser.getId());
//
//        Map<String,Object> result = new HashMap<>();
//        result.put("name",username);
//        result.put("avatar","https://wpimg.wallstcn.com/f778738c-e4f8-4870-b634-56703b4acafe.gif");
//        result.put("roles","[\"admin\"]");
//        //菜单权限数据
//        result.put("routers",routerVolist);
//        //按钮权限数据
//        result.put("buttons",permsList);
//        return result;
//    }

}
